package com.biofuelsfinder;

import java.util.ArrayList;
import java.util.List;
import java.lang.IllegalStateException;
import java.lang.NullPointerException;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.database.Cursor;
import android.widget.SimpleCursorAdapter;
import android.content.Context;



public class RetailerList extends ListActivity{

	private biofuelsDB biofuelsDB;
    
    public void onCreate(Bundle savedInstanceState) {
        try{
        	super.onCreate(savedInstanceState);
        	setContentView(R.layout.retailer_list);
            biofuelsDB = new biofuelsDB(this);
        }catch(Throwable e){
                Log.e("biofuelsDB",e.toString());
        }
    }
    
    public void fillData(Context ctx, String fueltype){
    	Log.i("Info - fueltype", fueltype.toString());
    	ArrayList<String> items = new ArrayList<String>();
        /*Cursor retailers;
        try{
        	retailers = biofuelsDB.getRetailers(fueltype.toString());
        	int rcount = retailers.getCount();
        	for(int i = 0; i < rcount; i++){
                try{
                    items.add(retailers.getString(retailers.getColumnIndex("name")));
                } catch(IllegalStateException e){
                    Log.e("blah", e.toString());
                }
                //items.add(user.lastName);
                //items.add(user.country);
        	}	
        } catch (NullPointerException e){
        	Log.e("blah", e.toString());
        }*/
        

        items.add("Blah1");
        items.add("Blah2");
        items.add("Blah3");

        ListAdapter adapter = null;
        try{
        	adapter = new ArrayAdapter<String>(ctx, R.layout.retailers_row, items);	
        } catch (NullPointerException e){
        	Log.e("Creating ArrayAdapter", e.toString());
        }
        
        try{
        	setListAdapter(adapter);
        } catch (NullPointerException e){
        	Log.e("biofuelsDB", e.getMessage().toString());
        }
    }

}


